﻿//JumbotCms_4.1 Final
using System;
using System.Web;
using System.Data;
using JumbotCms.DataObject;
namespace JumbotCms.Common
{
    public class DataPageCount
    {
        Jumbot.DataOper.DbOperHandler doh = null;
        private Channel Channel;
        public DataPageCount(Jumbot.DataOper.DbOperHandler Doh, string _ChannelId)
        {
            doh = Doh;
            Channel = new Channel();
            if (_ChannelId == string.Empty || _ChannelId == "0")
                Channel.GetPartColumn("0", doh);
            else
                Channel.GetPartColumn(_ChannelId, doh);
        }
        /// <summary>
        /// 栏目内容页数
        /// </summary>

        public int Class(string _classId, bool _Child)
        {
            doh.Reset();
            doh.SqlCmd = "SELECT [PageSize],[Code] FROM [jcms_normal_class] WHERE [ChannelId]=" + Channel.Id + " AND [Id]=" + _classId;
            int countNum = 0;
            int PageSize = Jumbot.Common.Validator.StrToInt(doh.GetDataTable().Rows[0]["PageSize"].ToString(), 0);
            string ClassCode = doh.GetDataTable().Rows[0]["Code"].ToString();
            if (PageSize == 0) PageSize = 20;
            string pStr = string.Empty;
            if (!_Child)
                pStr = " [ClassID]=" + _classId + " AND [IsPass]=1 AND [ChannelId]=" + Channel.Id;
            else
                pStr = " [ClassID] in (Select id FROM [jcms_normal_class] WHERE [Code] LIKE '" + ClassCode + "%') AND [IsPass]=1 AND [ChannelId]=" + Channel.Id;
            doh.Reset();
            doh.ConditionExpress = pStr;
            countNum = doh.Count("jcms_module_" + Channel.Type);
            return Jumbot.Common.Int.PageCount(countNum, PageSize);
        }
    }
}
